jQuery(function($) {
	loadData();
	
});
function changeChongzhiNum(obj){
	obj.value=obj.value.replace(/[^-\d]/g,'')
	var count = obj.value;
	if(count == "" || count == "0"){
		parent.window.$("#promptTxt").html("请输入正确的金币数量");
	}else{
		parent.window.$("#promptTxt").html("你好，您将给"+parent.window.$("#chongzhiDialog_userId").html()+"账户充值"+count+"个金币");
	}
}
function openChargeDialog(userId,goldCoinCount,headImg,nickName,father,now){
	$("#chongzhiDialog_userId").html(userId);
	$("#chongzhiDialog_goldCoinCount").html(goldCoinCount);
    var count = $("#chongzhi_num").val();
    if(count!=null){
        $("#promptTxt").html("你好，您将给"+userId+"账户充值1个金币");
        $("#chongzhi_num").attr("onkeyup",window.frameElement.id+".contentWindow.changeChongzhiNum(this)");
    }
	$("#confrimDialog #avatar").attr("src",headImg);
	$("#confrimDialog #confrim_nickName").html(nickName);
	$("#confrimDialog #confrim_father").html(father);
	$("#confrimDialog #confrim_now").html(now);
	
	var confrimDialog = $("#confrimDialog");
	
	parent.window.Index.dialog({
		resizable: false,
		dialogClass: "no-close",
		width: '620',
		context:$("#chongzhiDialog").html(),
		modal: true,
		title: "<div class='widget-header'><h4 class='smaller'><i class='ace-icon fa fa-rmb yellow'></i> 玩家充值</h4></div>",
		title_html: true,
		buttons: [
			{
				html: "<i class='ace-icon glyphicon glyphicon-ok bigger-110'></i>&nbsp; 确定",
				"class" : "btn btn-primary btn-minier",
				click: function() {
                    var confrimTips = '';
                    count = parent.window.$("#chongzhi_num").val();;
                    if(count == undefined){
                        count = '';
                    }
                    var goldLv = parent.window.$("#goldLv").val();
                    if(goldLv == undefined){
                        goldLv = '';
                    }
                    if((count == '') && (goldLv == '')){
                        return;
                    }
                    if(count != ""){
                        confrimTips = count;
                    }else if(goldLv != ""){
                        confrimTips = parent.window.$("#goldLv").find("option:selected").text();
                    }
					parent.window.Index.dialog({
						resizable: false,
						dialogClass: "no-close",
						width: '420',
						context:confrimDialog.html(),
						modal: true,
						title: "<div class='widget-header'><h4 class='smaller'><i class='ace-icon fa fa-rmb yellow'></i> 玩家充值 - 确认信息</h4></div>",
						title_html: true,
						buttons:[{
							html: "<i class='ace-icon glyphicon glyphicon-ok bigger-110'></i>&nbsp; 确定",
							"class" : "btn btn-primary btn-minier",click: function() {
								$.ajax({
									type:"POST",
									url:ctx+"/admin/usermanager/chargeJB",
									data:"userId="+userId+"&count="+count+"&goldLv="+goldLv,
									cache:false,
									success:function(data){
										if(data.code == 0){
											alert(data.msg);
										}else {
                                            refreshPage();
										}
									}
								});
								parent.window.$( this ).dialog( "close" );
							}
							},
							{html: "<i class='ace-icon glyphicon glyphicon-remove bigger-110'></i>&nbsp; 取消",
								"class" : "btn btn-minier",click: function() {
									parent.window.$( this ).dialog( "close" );
								}}]
					})
                    parent.window.$("#confrim_thistime").html(confrimTips);
					return;
					
				}
			}
			,
			{
				html: "<i class='ace-icon glyphicon glyphicon-remove bigger-110'></i>&nbsp; 取消",
				"class" : "btn btn-minier",
				click: function() {
					parent.window.$( this ).dialog( "close" );
				}
			}
		]
	});
}
function loadData(){
	var data = $("#playerQueryFOrm").serialize();
	if(!data && initAgentId){
		data = "agentId="+initAgentId;
	}
	$.ajax({
		type:"POST",
		url:dataUrl,
		data:data,
		cache:false,
		success:function(data){
			$("#context").html(data);
		}
	});
}
var returnTop = function(){
	initUserId = null;
	$('#queryInputAgentId').val('');
	refreshPage();
}

